<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222">











<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0f81ff2f.js","daovoice")
  daovoice('init', {
      app_id: "9c84d93b"
    });
  daovoice('update');
  </script>












<link href="/personblog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/personblog/css/main.css?v=6.1.0" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/personblog/images/apple-touch-icon-next.png?v=6.1.0">


  <link rel="icon" type="image/png" sizes="32x32" href="/personblog/images/favicon-32x32-next.png?v=6.1.0">


  <link rel="icon" type="image/png" sizes="16x16" href="/personblog/images/favicon-16x16-next.png?v=6.1.0">


  <link rel="mask-icon" href="/personblog/images/logo.svg?v=6.1.0" color="#222">







<script>
    (function(){
        if(''){
            if (prompt('请输入文章密码') !== ''){
                alert('密码错误！');
                history.back();
            }
        }
    })();
</script>


<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/personblog/',
    scheme: 'Muse',
    version: '6.1.0',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: false,
    fastclick: false,
    lazyload: false,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>


  




  <meta name="description" content="1.Servlet执行流程客户端发出http请求,web服务器将请求转发到servlet容器，servlet容器解析url并根据web.xml找到对应的servlet，并将request、response对象传递给找到的servlet，servlet根据request就可以知道是谁发出请求，请求信息及其他信息，当servlet处理完业务逻辑后将信息放入到response并响应到客户端。  2.Sp">
<meta name="keywords" content="java,面试">
<meta property="og:type" content="article">
<meta property="og:title" content="2017java面试题(技术面试）">
<meta property="og:url" content="http://zhangsnke.gitee.io/2018/04/28/javaInterview1/index.html">
<meta property="og:site_name" content="Zhangsnke&#39;s Blog">
<meta property="og:description" content="1.Servlet执行流程客户端发出http请求,web服务器将请求转发到servlet容器，servlet容器解析url并根据web.xml找到对应的servlet，并将request、response对象传递给找到的servlet，servlet根据request就可以知道是谁发出请求，请求信息及其他信息，当servlet处理完业务逻辑后将信息放入到response并响应到客户端。  2.Sp">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2018-04-11T08:41:34.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2017java面试题(技术面试）">
<meta name="twitter:description" content="1.Servlet执行流程客户端发出http请求,web服务器将请求转发到servlet容器，servlet容器解析url并根据web.xml找到对应的servlet，并将request、response对象传递给找到的servlet，servlet根据request就可以知道是谁发出请求，请求信息及其他信息，当servlet处理完业务逻辑后将信息放入到response并响应到客户端。  2.Sp">






  <link rel="canonical" href="http://zhangsnke.gitee.io/2018/04/28/javaInterview1/"/>



<script type="text/javascript" id="page.configurations">
  CONFIG.page = {
    sidebar: "",
  };
</script>

  <title>2017java面试题(技术面试） | Zhangsnke's Blog</title>
  









  <noscript>
  <style type="text/css">
    .use-motion .motion-element,
    .use-motion .brand,
    .use-motion .menu-item,
    .sidebar-inner,
    .use-motion .post-block,
    .use-motion .pagination,
    .use-motion .comments,
    .use-motion .post-header,
    .use-motion .post-body,
    .use-motion .collection-title { opacity: initial; }

    .use-motion .logo,
    .use-motion .site-title,
    .use-motion .site-subtitle {
      opacity: initial;
      top: initial;
    }

    .use-motion {
      .logo-line-before i { left: initial; }
      .logo-line-after i { right: initial; }
    }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
<a href="https://github.com/zxk318www"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_left_gray_6d6d6d.png" alt="Fork me on GitHub"></a>
    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/personblog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zhangsnke's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>




<nav class="site-nav">
  
    <ul id="menu" class="menu">
      
        
        
          
  
  <li class="menu-item menu-item-home menu-item-active">
    <a href="/personblog/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-about">
    <a href="/personblog/about/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-tags">
    <a href="/personblog/tags/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />标签</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-categories">
    <a href="/personblog/categories/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-th"></i> <br />分类</a>
</li>

      
        
        
          
  
  <li class="menu-item menu-item-archives">
    <a href="/personblog/archives/" rel="section">
      <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档</a>
</li>

      

      
      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />搜索</a>
        </li>
      
    </ul>
  

  
    

  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



  



</div>
    </header>

    


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zhangsnke.gitee.io/personblog/2018/04/28/javaInterview1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Zhangsnke">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="https://s1.ax1x.com/2018/04/04/C9BbPU.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zhangsnke's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">2017java面试题(技术面试）</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-04-28T10:45:56+08:00">2018-04-28</time>
            

            
            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/personblog/categories/java面试题/" itemprop="url" rel="index"><span itemprop="name">java面试题</span></a></span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="1-Servlet执行流程"><a href="#1-Servlet执行流程" class="headerlink" title="1.Servlet执行流程"></a><strong>1.Servlet执行流程</strong></h1><p>客户端发出http请求,web服务器将请求转发到servlet容器，servlet容器解析url并根据web.xml找到对应的servlet，并将request、response对象传递给找到的servlet，servlet根据request就可以知道是谁发出请求，请求信息及其他信息，当servlet处理完业务逻辑后将信息放入到response并响应到客户端。</p>
<hr>
<h1 id="2-SpringMVC的执行流程"><a href="#2-SpringMVC的执行流程" class="headerlink" title="2.SpringMVC的执行流程"></a><strong>2.SpringMVC的执行流程</strong></h1><p>SpringMVC是由dispatchservlet为核心的分层控制框架。首先客户端发出一个请求web服务器解析请求URL并去匹配dispatchservlet的映射URL，如果匹配的上就将这个请求放入到dispatchservlet，dispatchservlet根据mapping映射配置去寻找到相应得handle，然后把处理权交给找到的handle，handle封装了处理业务逻辑的代码，当handle处理完后会返回一个逻辑视图modelandview给dispatchservlet，此时的modelandview是一个逻辑视图不是一个正式视图，所以dispatchservlet会通过viewersource视图资源去解析modelandview，然后将解析后的参数放到view中返回到客户端并展现。</p>
<hr>
<h1 id="3-给定一个txt文件，如何得到某字符出现的次数"><a href="#3-给定一个txt文件，如何得到某字符出现的次数" class="headerlink" title="3.给定一个txt文件，如何得到某字符出现的次数"></a><strong>3.给定一个txt文件，如何得到某字符出现的次数</strong></h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">File file = <span class="keyword">new</span> File(<span class="string">"E://test.txt"</span>);</span><br><span class="line">InputStream is = <span class="keyword">new</span> FileInputStream(file);</span><br><span class="line"><span class="keyword">byte</span>[] b= <span class="keyword">new</span> <span class="keyword">byte</span>[<span class="number">1024</span>]; </span><br><span class="line"><span class="keyword">int</span> a = is.read(b);</span><br><span class="line">String str[] = <span class="keyword">new</span> String(b,<span class="number">0</span>,a).split(<span class="string">""</span>);</span><br><span class="line"><span class="keyword">int</span> count = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i =<span class="number">0</span>;i&lt;str.length;i++)&#123;</span><br><span class="line">	<span class="keyword">if</span>(<span class="string">"a"</span>.equals(str[i]))&#123;</span><br><span class="line">		count ++;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line">System.out.println(count);</span><br></pre></td></tr></table></figure>
<hr>
<h1 id="4-Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）"><a href="#4-Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）" class="headerlink" title="4.Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）"></a><strong>4.Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）</strong></h1><ul>
<li><p><font color="red">单例模式：</font><br>单例模式核心只需要new一个实例对象的模式，比如数据库连接，在线人数等，一些网站上看到的在线人数统计就是通过单利模式实现的，把一个计时器存放在数据库或者内存中，当有人登录的时候取出来+1再放回去，有人退出的时候取出来-1再放回去。但是当有两个人同时登录的时候，会同时取出计数器，同时+1，同时放回去，这样的话数据就会错误，所以需要一个全局变量的对象给全部人使用，只需啊哟new出一个实例对象，这就是单例模式的应用，并且单例模式节省资源，因为它控制了实例对象迭代个数，有利于gc回收。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SingletonClass</span></span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">volatile</span> SingletonClass instance=<span class="keyword">null</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> SingletonClass <span class="title">getInstance</span><span class="params">()</span></span>&#123;</span><br><span class="line">            <span class="keyword">synchronized</span>(SingletonClass.class)&#123;</span><br><span class="line">                <span class="keyword">if</span>(instance==<span class="keyword">null</span>)&#123;</span><br><span class="line">                    instance=<span class="keyword">new</span> SingletonClass();</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        <span class="keyword">return</span> instance;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="title">SingletonClass</span><span class="params">()</span></span>&#123;&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p><font color="red">策略模式：</font><br>就是将几个类中公共的方法提取到一个新的类中，从而使扩展更容易，保证代码的可移植性，可维护性强。比如有个需求是写鸭子对象，鸭子有叫、飞、外形这三种方法，如果每个鸭子类都写这三个方法会出现代码冗余，这时候我们把鸭子中的叫、飞、外形这三个方法提取出来，放到鸭子父类中，让每个鸭子都继承这个鸭父类。重新这三个方法，这样封装的代码可移植性强，当用户提出新的需求时，比如说鸭子游泳，那么对于我们程序员来讲就非常简单，只需要在鸭父类中添加一个游泳的方法，所有继承这个父类的鸭子都有了这个方法，重写游泳方法即可。</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//简单工厂</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Factory</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> ISample <span class="title">creator</span><span class="params">(<span class="keyword">int</span> which)</span></span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (which==<span class="number">1</span>)</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> SampleA();</span><br><span class="line">        <span class="keyword">else</span> <span class="keyword">if</span> (which==<span class="number">2</span>)</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">new</span> SampleB();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//抽象工厂</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="class"><span class="keyword">class</span> <span class="title">Factory</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> Sample <span class="title">creator</span><span class="params">()</span></span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> Sample2 <span class="title">creator</span><span class="params">(String name)</span></span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">SimpleFactory</span> <span class="keyword">extends</span> <span class="title">Factory</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Sample <span class="title">creator</span><span class="params">()</span></span>&#123;</span><br><span class="line">        .........</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SampleA</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Sample2 <span class="title">creator</span><span class="params">(String name)</span></span>&#123;</span><br><span class="line">        .........</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Sample2A</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BombFactory</span> <span class="keyword">extends</span> <span class="title">Factory</span></span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Sample <span class="title">creator</span><span class="params">()</span></span>&#123;</span><br><span class="line">        ......</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SampleB</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> Sample2 <span class="title">creator</span><span class="params">(String name)</span></span>&#123;</span><br><span class="line">        ......</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Sample2B</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>以上两种为简单和抽象工厂模式代码</p>
<ul>
<li><font color="red">工厂模式：</font><br>简单的工厂模式主要是统一提供实例对象的引用，通过工厂模式接口获取实例对象的引用。比如一个登录功能，后端有三个类，Controller类、interface类、实现接口的实现类。当客户端发出一个请求，当请求传到Controller类中时，Controller获取接口的引用对象，而实现接口的实现类中封装好了登录的业务逻辑代码。当你需要加一个注册需求的时候只需要在接口类中加一个注册方法，实现类中实现方法，Controller获取接口的引用对象即可，不需要改动原来的代码，这种做法可拓展性强。</li>
</ul>
<h1 id="5-冒泡排序、二分查找"><a href="#5-冒泡排序、二分查找" class="headerlink" title="5.冒泡排序、二分查找"></a><strong>5.冒泡排序、二分查找</strong></h1><ul>
<li><p>冒泡</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">mp</span><span class="params">(<span class="keyword">int</span> a[])</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> swap = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;a.length;i++)&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> j=i;j&lt;a.length;j++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(a[j]&gt;a[i])&#123;</span><br><span class="line">				swap = a[i];</span><br><span class="line">				a[i] = a[j];</span><br><span class="line">				a[j] = swap;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
<li><p>二分法查找</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">int</span> <span class="title">ef</span><span class="params">(<span class="keyword">int</span> a[],<span class="keyword">int</span> tag)</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> first = <span class="number">0</span>;</span><br><span class="line">	<span class="keyword">int</span> end = a.length;</span><br><span class="line">	<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;a.length;i++)&#123;</span><br><span class="line">		<span class="keyword">int</span> middle = (first+end)/<span class="number">2</span>;</span><br><span class="line">		<span class="keyword">if</span>(tag == a[middle])&#123;</span><br><span class="line">			<span class="keyword">return</span> middle;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(tag&gt;a[middle])&#123;</span><br><span class="line">			first = middle + <span class="number">1</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span>(tag&lt;a[middle])&#123;</span><br><span class="line">			end = middle - <span class="number">1</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>代码如上所示</p>
<hr>
<h1 id="6-对ajax的理解"><a href="#6-对ajax的理解" class="headerlink" title="6.对ajax的理解"></a><strong>6.对ajax的理解</strong></h1><p>Ajax为<font color="blue"> 异步请求，即局部刷新技术</font>，在传统的页面中，用户需要点击按钮或者事件触发请求，到刷新页面，而异步技术为不需要点击即可触发事件。(不需要刷新整个网页，而刷新部分网页数据)</p>
<hr>
<h1 id="7-父类与子类之间的调用顺序（打印结果）"><a href="#7-父类与子类之间的调用顺序（打印结果）" class="headerlink" title="7.父类与子类之间的调用顺序（打印结果）"></a><strong>7.父类与子类之间的调用顺序（打印结果）</strong></h1><ul>
<li>父类静态代码块</li>
<li>子类静态代码块</li>
<li>父类的构造方法</li>
<li>子类的构造方法</li>
<li>子类的普通方法</li>
<li>重写父类的方法，则打印重写后的方法</li>
</ul>
<hr>
<h1 id="8-内部类与外部类的调用"><a href="#8-内部类与外部类的调用" class="headerlink" title="8.内部类与外部类的调用"></a><strong>8.内部类与外部类的调用</strong></h1><ul>
<li>内部类可以直接调用外部类包括平private的成员变量，使用外部类引用的this.关键字调用即可</li>
<li>外部类调用内部类需要建立内部类对象</li>
</ul>
<hr>
<h1 id="9-多线程"><a href="#9-多线程" class="headerlink" title="9.多线程"></a><strong>9.多线程</strong></h1><ul>
<li>一个进程是一个独立的运行环境，可以看做是一个程序，而线程可以看做是进程的一个任务，比如QQ是一个进程，而一个QQ窗口是一个线程。</li>
<li>在多线程程序中，多线程并发可以提高程序的效率，CPU不会因为某个线程等待资源而进入空闲状态，它会把资源让给其他的线程。</li>
<li>用户线程就是我们开发程序是创建的线程，而守护线程为系统线程，如JVM虚拟中的GC。</li>
<li>线程的优先级别：每一个线程都有优先级别，有限制级高的可以先获取CPU资源使该线程从就绪状态转为运行状态。也可以自定义线程的优先级别。</li>
<li>死锁：至少两个以上线程争取两个以上CPU资源，避免死锁就避免使用嵌套锁，只需要在他们需要同步的地方加锁和避免无限等待。（发生死锁的四个条件：互斥条件、请求和保存条件、不剥夺条件、环路等条件）。<br><font color="blue">1 互斥条件：</font>指进程对所分配到的资源进行排它性使用，即在一段时间内某个资源只由一个进程占用。若果此时还有其他进程请求资源，则请求者只能等待，直到战友的进程用完释放。<br><font color="blue">2 请求和保持条件：</font>指进程以及保持了至少一个资源，但又提出了新的资源请求，而该资源已经被其他进程占有，此时请求进程阻塞，但又对自己已获得的其他资源保持不放。<br><font color="blue">3 不剥夺条件：</font>指进程已获得的资源，在未使用完之前，不能剥夺，只能在使用完时由自己释放。<br><font color="blue">4 环路等待条件：</font>指在发生死锁时，必然存在一个进程——资源的环形链，即进程集合{p0,p1,p2,….,pn}中的p0正在等待一个p1占用的资源；p1正在等待p2占用的资源，….,pn增在等待已被p0占用的资源。</li>
</ul>
<hr>
<h1 id="10-AOP与IOC的概念（即spring的核心）"><a href="#10-AOP与IOC的概念（即spring的核心）" class="headerlink" title="10.AOP与IOC的概念（即spring的核心）"></a><strong>10.AOP与IOC的概念（即spring的核心）</strong></h1><ul>
<li>IOC:Spring是开源框架，使用框架可以使我们减少工作量，提高工作效率并且它是分层结构，即相对应的层处理对应的业务逻辑，减少代码的耦合度。而spring的核心是IOC控制反转和AOP面向切面编程。IOC控制反转主要强调的是程序之间的关系是由容器控制的，容器控制对象，控制了对外部资源的获取。而反转即为，在传统的编程中都是由我们创建对象获取依赖对象，而在IOC中是由容器帮我们创建好对象并注入依赖对象，正是容器帮我们查找和注入对象，对象是被获取，所以叫反转。</li>
<li>AOP:面向切面编程，主要是管理系统层的业务，比如日志，权限，事物等。AOP是将封装好的对象剖开，找出其中对多个对象产生影响的公共行为，并将其封装为一个可重用的模块，这个模块被命名为切面（aspect），切面讲那些与业务逻辑无关，却被业务模块共同调用的逻辑提取并封装起来，减少了系统中的重复代码，降低了模块间的耦合度，同时提高了系统的可维护性。</li>
</ul>
<hr>
<h1 id="11-hibernate的核心思想"><a href="#11-hibernate的核心思想" class="headerlink" title="11.hibernate的核心思想"></a><strong>11.hibernate的核心思想</strong></h1><p>hibernate的核心思想就是ROM对象关系映射机制，它是将表与表之间的操作映射成对象与对象之间的操作。也就是从数据库中提取的信息会自动按照你设置的映射要求封装成特定的对象。所以hibernate就是通过将数据表实体类的映射，使得对对象的修改对应数据行的修改。</p>
<hr>
<h1 id="12-最优删除某字符串的某个字符"><a href="#12-最优删除某字符串的某个字符" class="headerlink" title="12.最优删除某字符串的某个字符"></a><strong>12.最优删除某字符串的某个字符</strong></h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">///////////////////////////////////////////////////////////////////////  </span></span><br><span class="line"><span class="comment">// Delete all characters in pStrDelete from pStrSource  </span></span><br><span class="line"><span class="comment">///////////////////////////////////////////////////////////////////////  </span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">DeleteChars</span><span class="params">(<span class="keyword">char</span>* pStrSource, <span class="keyword">const</span> <span class="keyword">char</span>* pStrDelete)</span>  </span></span><br><span class="line"><span class="function"></span>&#123;  </span><br><span class="line">      <span class="keyword">if</span>(NULL == pStrSource || NULL == pStrDelete)  </span><br><span class="line">            <span class="keyword">return</span>;  </span><br><span class="line">   </span><br><span class="line">      <span class="comment">// Initialize an array, the index in this array is ASCII value.  </span></span><br><span class="line">      <span class="comment">// All entries in the array, whose index is ASCII value of a  </span></span><br><span class="line">      <span class="comment">// character in the pStrDelete, will be set as 1.  </span></span><br><span class="line">      <span class="comment">// Otherwise, they will be set as 0.  </span></span><br><span class="line">      <span class="keyword">const</span> unsigned <span class="keyword">int</span> nTableSize = <span class="number">256</span>;  </span><br><span class="line">      <span class="keyword">int</span> hashTable[nTableSize];  </span><br><span class="line">      memset(hashTable, <span class="number">0</span>, sizeof(hashTable));  </span><br><span class="line">   </span><br><span class="line">      <span class="keyword">const</span> <span class="keyword">char</span>* pTemp = pStrDelete;  </span><br><span class="line">      <span class="keyword">while</span> (<span class="string">'\0'</span> != *pTemp)  </span><br><span class="line">      &#123;  </span><br><span class="line">            hashTable[*pTemp] = <span class="number">1</span>;  </span><br><span class="line">            ++ pTemp;  </span><br><span class="line">      &#125;  </span><br><span class="line">   </span><br><span class="line">      <span class="keyword">char</span>* pSlow = pStrSource;  </span><br><span class="line">      <span class="keyword">char</span>* pFast = pStrSource;  </span><br><span class="line">      <span class="keyword">while</span> (<span class="string">'\0'</span> != *pFast)  </span><br><span class="line">      &#123;  </span><br><span class="line">            <span class="comment">// if the character is in pStrDelete, move both pStart and  </span></span><br><span class="line">            <span class="comment">// pEnd forward, and copy pEnd to pStart.  </span></span><br><span class="line">            <span class="comment">// Otherwise, move only pEnd forward, and the character  </span></span><br><span class="line">            <span class="comment">// pointed by pEnd is deleted  </span></span><br><span class="line">            <span class="keyword">if</span>(<span class="number">1</span> != hashTable[*pFast])  </span><br><span class="line">            &#123;  </span><br><span class="line">                  *pSlow = *pFast;  </span><br><span class="line">                  ++ pSlow;  </span><br><span class="line">            &#125;  </span><br><span class="line">   </span><br><span class="line">            ++pFast;  </span><br><span class="line">      &#125;  </span><br><span class="line">   </span><br><span class="line">      *pSlow = <span class="string">'\0'</span>;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>代码如上</p>
<hr>
<h1 id="13-ArrayList与LinkedList的区别"><a href="#13-ArrayList与LinkedList的区别" class="headerlink" title="13.ArrayList与LinkedList的区别"></a><strong>13.ArrayList与LinkedList的区别</strong></h1><p>都是实现List接口的列表。ArrayList是<font color="red">基于数组的数据结构，LinkedList是基于链表的数据结构</font>，当获取特定元素时，ArrayList效率比较快，它通过数组下标即可获取，而LinkedList则需要移动指针。当存储和删除元素时LinkedList效率比较快，只需要移动指针指定位置即可增加和删除，而ArrayList需要移动数据。</p>
<hr>
<h1 id="14-数据库优化"><a href="#14-数据库优化" class="headerlink" title="14.数据库优化"></a><strong>14.数据库优化</strong></h1><ul>
<li>选择合适的字段，比如邮箱字段可以设定char(6),尽量把字段设置为not null,这样查询的时候数据库就不需要比较null值</li>
<li>使用关联查询（Left join on）查询代替子查询</li>
<li>使用union联合查询手动创建临时表</li>
<li>开启事物，当数据库执行多条语句出现错误时，事物会回滚，可以维护数据库的完整性</li>
<li>使用外键，事物可以维护数据的完整性但是它却不能保证数据的关联性，使用外键可以保证数据的关联性</li>
<li>使用索引，索引是提高数据库性能的常用方法，它可以令数据库服务器比没有索引快的多的速度检索特定的行，特别是对于max,min,order by查询时，效果更明显</li>
<li>优化的查询语句，绝大多数情况下，使用索引可以提高查询的速度，但如果sql语句使用不恰当的话，索引无法发挥它的特性</li>
</ul>
<hr>
<h1 id="15-Tomcat服务器优化（内存，并发连接数，缓存）"><a href="#15-Tomcat服务器优化（内存，并发连接数，缓存）" class="headerlink" title="15.Tomcat服务器优化（内存，并发连接数，缓存）"></a><strong>15.Tomcat服务器优化（内存，并发连接数，缓存）</strong></h1><ul>
<li>内存优化：<br>主要是对Tomcat启动参数进行优化，我们可以在Tomcat启动脚本中修改它的最大内存数等</li>
<li>线程数优化：<br>Tomcat的并发链接参数，主要在Tomcat配置文件中server.xml中配置，比如修改最小空闲连接线程数，用于提高系统处理能力等</li>
<li>优化缓存：<br>打开压缩功能，修改参数，比如压缩的输出内容大小默认为2KB,可以适当地修改</li>
</ul>
<hr>
<h1 id="16-HTTP协议"><a href="#16-HTTP协议" class="headerlink" title="16.HTTP协议"></a><strong>16.HTTP协议</strong></h1><ul>
<li>常用的请求方法：get、post</li>
<li><p>Get和Post的区别：<br>传送数据，get携带参数与访问地址传送，用户是可以看见，这样的话信息会不安全，导致信息泄露。而Post则将字段与对应值封装在实体中传送，这个过程用户是不可见的。Get传递参数有限制，而Post无限制</p>
<hr>
</li>
</ul>
<h1 id="17-TCP-UDP协议"><a href="#17-TCP-UDP协议" class="headerlink" title="17.TCP/UDP协议"></a><strong>17.TCP/UDP协议</strong></h1><p>TCP和UDP协议都属于<font color="red">传输层协议</font>。其中TCP提供IP环境下的数据<font color="red">可靠传输</font>。它提供的服务包括了数据流传送、可靠性、有效流控、全双工操作和多路复用。通过面向连接、端到端和可靠的数据包发送。通俗说，它事先为发送的数据开辟出连接好的通道，然后再进行数据发送。UDP<font color="red">则不为IP提供可靠性、流控或差错恢复功能</font>。一般来说，TCP对应的可靠性要求高的应用，UDP对应的是可靠性要求低，传输经济的应用。</p>
<table>
<thead>
<tr>
<th>特点</th>
<th style="text-align:center">TCP</th>
<th style="text-align:center">UDP</th>
</tr>
</thead>
<tbody>
<tr>
<td>是否连接</td>
<td style="text-align:center">面向连接</td>
<td style="text-align:center">面向非连接</td>
</tr>
<tr>
<td>传输可靠性</td>
<td style="text-align:center">可靠地</td>
<td style="text-align:center">不可靠的</td>
</tr>
<tr>
<td>应用场合</td>
<td style="text-align:center">传输大量的数据</td>
<td style="text-align:center">少量数据</td>
</tr>
<tr>
<td>速度</td>
<td style="text-align:center">慢</td>
<td style="text-align:center">快</td>
</tr>
</tbody>
</table>
<hr>
<h1 id="18-Java集合类框架的基本接口有哪些"><a href="#18-Java集合类框架的基本接口有哪些" class="headerlink" title="18.Java集合类框架的基本接口有哪些"></a><strong>18.Java集合类框架的基本接口有哪些</strong></h1><p>总共有两大接口：<font color="red">Collection </font>和<font color="red">Map</font> ，一个元素集合，一个是键值对集合； 其中List和Set接口继承了Collection接口，一个是有序元素集合，一个是无序元素集合； 而ArrayList和 LinkedList 实现了List接口，HashSet实现了Set接口，这几个都比较常用； HashMap 和HashTable实现了Map接口，并且HashTable是线程安全的，但是HashMap性能更好。</p>
<p>java.util.Collection [I]<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">java.util.Collection [I]</span><br><span class="line"></span><br><span class="line">|—java.util.List [I]</span><br><span class="line"></span><br><span class="line">    |—java.util.ArrayList [C]</span><br><span class="line"></span><br><span class="line">    |—java.util.LinkedList [C]</span><br><span class="line"></span><br><span class="line">    |—java.util.Vector [C]</span><br><span class="line"></span><br><span class="line">        |—java.util.Stack [C]</span><br><span class="line"></span><br><span class="line">|—java.util.Set [I]</span><br><span class="line"></span><br><span class="line">    |—java.util.HashSet [C]</span><br><span class="line"></span><br><span class="line">    |—java.util.SortedSet [I]</span><br><span class="line"></span><br><span class="line">        |—java.util.TreeSet [C]</span><br></pre></td></tr></table></figure></p>
<p>java.util.Map [I]<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">|—java.util.SortedMap [I]</span><br><span class="line"></span><br><span class="line">    |—java.util.TreeMap [C]</span><br><span class="line"></span><br><span class="line">|—java.util.Hashtable [C]</span><br><span class="line"></span><br><span class="line">|—java.util.HashMap [C]</span><br><span class="line"></span><br><span class="line">    |—java.util.LinkedHashMap [C]</span><br><span class="line"></span><br><span class="line">|—java.util.WeakHashMap [C]</span><br></pre></td></tr></table></figure></p>
<font color="blue">Java集合类里最基本的接口有：<br>Collection：单列集合的根接口<br>List：元素有序  可重复<br>ArrayList：类似一个长度可变的数组 。适合查询，不适合增删<br>LinkedList：底层是双向循环链表。适合增删，不适合查询。<br>Set：元素无序，不可重复<br>HashSet：根据对象的哈希值确定元素在集合中的位置<br>TreeSet: 以二叉树的方式存储元素，实现了对集合中的元素排序<br>Map：双列集合的根接口，用于存储具有键（key）、值（value）映射关系的元素。<br>HashMap：用于存储键值映射关系，不能出现重复的键key<br>TreeMap：用来存储键值映射关系，不能出现重复的键key，所有的键按照二叉树的方式排列</font>

<hr>
<h1 id="19-类加载过程"><a href="#19-类加载过程" class="headerlink" title="19.类加载过程"></a><strong>19.类加载过程</strong></h1><p>遇到一个新的类时，<font color="red">首先</font>会到方法区中去找class文件，如果没有找到就回去硬盘中找class文件，找到后返回，将class文件加载到方法区中。<font color="red">其次</font>在类加载的时候，静态成员变量会被分配到方法区的静态区域，非静态成员变量分配到非静态区域，<font color="red">然后</font>开始给静态成员变量初始化，赋默认值，<font color="red">赋完默认值后</font>，会根据静态成员变量书写的位置赋显示值，然后执行静态代码。当所有的静态代码执行完，类加载才算完成。</p>
<hr>
<h1 id="20-对象的创建"><a href="#20-对象的创建" class="headerlink" title="20.对象的创建"></a><strong>20.对象的创建</strong></h1><ul>
<li>遇到一个新类时，会进行类的加载，定位到class文件</li>
<li>对所有静态成员变量初始化，静态代码块也会执行，而且只有类加载的时候执行一次</li>
<li>New对象时，JVM会在堆中分配一个足够大的存储空间</li>
<li>存储空间清空时，为所有的变量赋默认值，所有的对象引用赋值为null</li>
<li>根据书写的位置给一些字段初始化操作</li>
<li>调用构造器方法（没有继承）</li>
</ul>
<hr>
<h1 id="21-JVM优化"><a href="#21-JVM优化" class="headerlink" title="21.JVM优化"></a><strong>21.JVM优化</strong></h1><ul>
<li>设置参数，设置JVM的最大内存数</li>
<li>垃圾回收器的选择</li>
</ul>
<hr>
<h1 id="22-高并发处理"><a href="#22-高并发处理" class="headerlink" title="22.高并发处理"></a><strong>22.高并发处理</strong></h1><p>了解一点高并发性问题，比如一万个人抢一张票时，如何保证票在没买走的情况下所有人都能看见这张票。显然，不能用同步机制，因为Synchronize是锁同步一次只能一个人进行。这时候可以用到锁机制，采用乐观锁可以解决这个问题。乐观锁的简单意思是在不锁定表的情况下，利用业务的控制来解决并发问题这样既保证了数据的可读性，又保证数据的排他性，保证性能的同事解决了并发带来的脏读问题。（注：乐观锁的实现原理是cas操作，java中轻量级锁也是基于cas实现的。悲观锁最大的问题就是阻塞问题。）</p>
<hr>
<h1 id="23-事物的理解"><a href="#23-事物的理解" class="headerlink" title="23.事物的理解"></a><strong>23.事物的理解</strong></h1><p>事物一般具有<font color="red">原子性、一致性、持久性、隔离性。</font></p>
<ul>
<li>原子性：是指一个事物中，要么全部执行成功，要么全部失败滚回。</li>
<li>一致性：事物执行之前和执行之后都处于一致性状态</li>
<li>持久性：事物多数据的操作是永久的</li>
<li>隔离性：当一个事物正在对数据进行操作时，另一个事物不可以对数据进行操作，也就是多个并发书屋之间相互隔离</li>
</ul>
<hr>
<h1 id="24-Struts工作流程"><a href="#24-Struts工作流程" class="headerlink" title="24.Struts工作流程"></a><strong>24.Struts工作流程</strong></h1><ul>
<li>客户端发出一个请求到servlet容器</li>
<li>请求经过一系列过滤杯filterdispatcher调用，filterdispatch通过actionMapper去找相对应的action</li>
<li>Actionmapper找到对应的action返回给filterdispatch，dispatch吧处理权交给actionproxy</li>
<li>Actionproxy通过配置文件找到对应的action类</li>
<li>Actionproxy创建一个actioninvocation的实例处理业务逻辑</li>
<li>一旦action处理完毕，actioninvocation负责根据struts.xml的配置找到对应的返回结果，返回结果一般是jsp页面</li>
</ul>

      
    </div>

    

    
    
    

<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
  
</div>

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://wx4.sinaimg.cn/mw690/0060lm7Tly1fq7f9mgftqj30yf11x793.jpg" alt="Zhangsnke 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://wx2.sinaimg.cn/mw690/0060lm7Tly1fq7f9yogljj30ox0qi76z.jpg" alt="Zhangsnke 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/personblog/tags/java/" rel="tag"><i class="fa fa-tag"></i> java</a>
          
            <a href="/personblog/tags/面试/" rel="tag"><i class="fa fa-tag"></i> 面试</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/personblog/2018/04/28/java2/" rel="next" title="java内存管理以及常量池">
                <i class="fa fa-chevron-left"></i> java内存管理以及常量池
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/personblog/2018/04/28/java_api/" rel="prev" title="java api调用">
                java api调用 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          

  
    <div class="comments" id="comments">
      <div id="uyan_frame"></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="https://s1.ax1x.com/2018/04/04/C9BbPU.jpg"
                alt="Zhangsnke" />
            
              <p class="site-author-name" itemprop="name">Zhangsnke</p>
              <p class="site-description motion-element" itemprop="description">java jsp</p>
          </div>

          
            <nav class="site-state motion-element">
              
                <div class="site-state-item site-state-posts">
                
                  <a href="/personblog/archives/">
                
                    <span class="site-state-item-count">6</span>
                    <span class="site-state-item-name">日志</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-categories">
                  <a href="/personblog/categories/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">3</span>
                    <span class="site-state-item-name">分类</span>
                  </a>
                </div>
              

              
                
                
                <div class="site-state-item site-state-tags">
                  <a href="/personblog/tags/index.html">
                    
                    
                      
                    
                      
                    
                      
                    
                      
                    
                    <span class="site-state-item-count">4</span>
                    <span class="site-state-item-name">标签</span>
                  </a>
                </div>
              
            </nav>
          

          

          
            <div class="links-of-author motion-element">
              
                <span class="links-of-author-item">
                  <a href="https://github.com/zxk318www" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i>GitHub</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:1137824821@qq.com" target="_blank" title="E-Mail"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://weibo.com/u/3487862312" target="_blank" title="Weibo"><i class="fa fa-fw fa-weibo"></i>Weibo</a>
                  
                </span>
              
            </div>
          

          
          

          
          

          
            
          
          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-Servlet执行流程"><span class="nav-number">1.</span> <span class="nav-text">1.Servlet执行流程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-SpringMVC的执行流程"><span class="nav-number">2.</span> <span class="nav-text">2.SpringMVC的执行流程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-给定一个txt文件，如何得到某字符出现的次数"><span class="nav-number">3.</span> <span class="nav-text">3.给定一个txt文件，如何得到某字符出现的次数</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）"><span class="nav-number">4.</span> <span class="nav-text">4.Java设计模式思想（单例模式，工厂模式，策略模式，共23中设计模式）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#5-冒泡排序、二分查找"><span class="nav-number">5.</span> <span class="nav-text">5.冒泡排序、二分查找</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#6-对ajax的理解"><span class="nav-number">6.</span> <span class="nav-text">6.对ajax的理解</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#7-父类与子类之间的调用顺序（打印结果）"><span class="nav-number">7.</span> <span class="nav-text">7.父类与子类之间的调用顺序（打印结果）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#8-内部类与外部类的调用"><span class="nav-number">8.</span> <span class="nav-text">8.内部类与外部类的调用</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#9-多线程"><span class="nav-number">9.</span> <span class="nav-text">9.多线程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#10-AOP与IOC的概念（即spring的核心）"><span class="nav-number">10.</span> <span class="nav-text">10.AOP与IOC的概念（即spring的核心）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#11-hibernate的核心思想"><span class="nav-number">11.</span> <span class="nav-text">11.hibernate的核心思想</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#12-最优删除某字符串的某个字符"><span class="nav-number">12.</span> <span class="nav-text">12.最优删除某字符串的某个字符</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#13-ArrayList与LinkedList的区别"><span class="nav-number">13.</span> <span class="nav-text">13.ArrayList与LinkedList的区别</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#14-数据库优化"><span class="nav-number">14.</span> <span class="nav-text">14.数据库优化</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#15-Tomcat服务器优化（内存，并发连接数，缓存）"><span class="nav-number">15.</span> <span class="nav-text">15.Tomcat服务器优化（内存，并发连接数，缓存）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#16-HTTP协议"><span class="nav-number">16.</span> <span class="nav-text">16.HTTP协议</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#17-TCP-UDP协议"><span class="nav-number">17.</span> <span class="nav-text">17.TCP/UDP协议</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#18-Java集合类框架的基本接口有哪些"><span class="nav-number">18.</span> <span class="nav-text">18.Java集合类框架的基本接口有哪些</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#19-类加载过程"><span class="nav-number">19.</span> <span class="nav-text">19.类加载过程</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#20-对象的创建"><span class="nav-number">20.</span> <span class="nav-text">20.对象的创建</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#21-JVM优化"><span class="nav-number">21.</span> <span class="nav-text">21.JVM优化</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#22-高并发处理"><span class="nav-number">22.</span> <span class="nav-text">22.高并发处理</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#23-事物的理解"><span class="nav-number">23.</span> <span class="nav-text">23.事物的理解</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#24-Struts工作流程"><span class="nav-number">24.</span> <span class="nav-text">24.Struts工作流程</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zhangsnke</span>

  

  
</div>




<div class="powered-by">
<i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv">
  本站访客数:<span id="busuanzi_value_site_uv"></span>
</span>
</div>
  <!-- <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动 v3.7.1</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/theme-next/hexo-theme-next">NexT.Muse</a> v6.1.0</div>
-->





<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共字</span>
</div>
        








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


























  
  
    <script type="text/javascript" src="/personblog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/personblog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/personblog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  


  


  <script type="text/javascript" src="/personblog/js/src/utils.js?v=6.1.0"></script>

  <script type="text/javascript" src="/personblog/js/src/motion.js?v=6.1.0"></script>



  
  

  
  <script type="text/javascript" src="/personblog/js/src/scrollspy.js?v=6.1.0"></script>
<script type="text/javascript" src="/personblog/js/src/post-details.js?v=6.1.0"></script>



  


  <script type="text/javascript" src="/personblog/js/src/bootstrap.js?v=6.1.0"></script>



  



	





  
    

    
      <!-- UY BEGIN -->
      <script type="text/javascript" src="http://v2.uyan.cc/code/uyan.js?uid=2161053"></script>
      <!-- UY END -->
    
  





  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/personblog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  
  

  

  

  

  


<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
</body>
</html>

